<template>
  <div>
    <h1>登录</h1>
    <table>
      <tr>
        <td>账号：</td>
        <td><input type="text" v-model="state.userName" /></td>
      </tr>
      <tr>
        <td>密码：</td>
        <td><input type="password" v-model="state.userPwd" /></td>
      </tr>
      <tr>
        <td></td>
        <td><input type="button" value="登录" @click="login" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router';
import { reactive, toRefs } from 'vue';
import axios from 'axios';
const route = useRoute();
const router = useRouter();

let data = reactive({
  state: {
    userName: '',
    userPwd: '',
  },
});

let { state } = toRefs(data);

const login = () => {
  axios({
    url: '/api/XinXi/GetLogin',
    method: 'get',
    params: state.value,
  })
    .then((res) => {
      if (res.data.data == -1) {
        alert('该用户不存在');
        return;
      } else if (res.data.data == -2) {
        alert('请使用普通用户登录');
        return;
      } else {
        alert('登录成功');
        router.push('/liebiao');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
